package com.bb.flow.service.imp;

import com.bb.flow.config.enumtype.NodeType;
import com.bb.flow.service.FlowDriver;
import com.bb.flow.service.imp.executor.node.ContainerNodeExecutor;
import com.bb.flow.service.imp.executor.node.FunctionNodeExecutor;
import com.bb.flow.service.imp.executor.node.JudgeNodeExecutor;
import com.bb.flow.service.imp.executor.node.SubFlowNodeExecutor;

import java.io.Serializable;

/**
 * @author bigbeard
 * 节点工厂类
 */
public class ExecuteFactory implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 创建节点执行器
     *
     * @param nodeType   节点类型
     * @param flowDriver 当前驱动
     * @return 节点执行器
     */
    public static AbstractNodeExecutor createNewNodeExecutor(NodeType nodeType, FlowDriver flowDriver) {
        switch (nodeType) {
            case JUDGE_NODE:
                return new JudgeNodeExecutor();
            case SUBFLOW_NODE:
                SubFlowNodeExecutor subFlowNodeExecutor = new SubFlowNodeExecutor();
                subFlowNodeExecutor.setFlowDriver(flowDriver);
                return subFlowNodeExecutor;
            case FUNCTION_NODE:
                return new FunctionNodeExecutor();
            case CONTAINER_NODE:
                ContainerNodeExecutor containerNodeExecutor = new ContainerNodeExecutor();
                containerNodeExecutor.setFlowDriver(flowDriver);
                return containerNodeExecutor;
            default:
                return null;

        }
    }
}
